package Thread;
class ThreadYield extends Thread{
    public ThreadYield(String name)
    {
        super(name);
    }
    @Override
    public void run()
    {
        for (int i=1;i<50;i++)
        {
            System.out.println(""+this.getName()+"-----"+i);
            if(i==30)
            {
                try {
                    this.sleep(50);//yield()暂停当前正在执行的线程对象，并执行其他线程
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        }
    }
}

public class Yield {
    public static void main(String[] args) {
        ThreadYield yt1 = new ThreadYield("张三");
        ThreadYield yt2 = new ThreadYield("李四");
        yt1.start();
        yt2.start();
    }
}

